package RecordManagement;

import java.nio.ByteBuffer;
import PagedFile.Buffer;

public class RM_BufferHandle {
	RM_FileHead rmFileHead;
	ByteBuffer contents;
	int pageNum;
	int nRecord;	
	
	private static FunctionalClass.Buffer_Bit_Operation bbop = new FunctionalClass.Buffer_Bit_Operation();
	
	public RM_BufferHandle(Buffer buf, RM_FileHead rmFileHead){
		this.contents = buf.contents;
		this.pageNum = buf.block.pageNum;
		this.rmFileHead = rmFileHead;
		nRecord = contents.getInt(0);
	}
	
	void SetNumRecord(int n) {
		nRecord = n;
		contents.putInt(0, n);
	}
	
	boolean SlotTest(int slotNum) {
		return bbop.bitTest(contents, RM_Manager.RM_PAGEHEAD_SIZE, slotNum);
	}
	
	void SlotSet(int slotNum) {
		bbop.bitSet(contents, RM_Manager.RM_PAGEHEAD_SIZE, slotNum);
	}
	
	byte[] GetRecordData(int slotNum) {
		byte[] data = new byte[rmFileHead.recordSize];
		contents.position(rmFileHead.firstRecordOffset+rmFileHead.recordSize*slotNum);
		contents.get(data);
		return data;
	}
}
